$(document).ready(function() {

	$('#page').find('img').each(function() {

		if($(this).hasClass('fancybox'))
		{
		
			var img = $(this).attr('src');
			
			var i = img.lastIndexOf('?');
			if(i != -1) {
				img = img.substr(0, i);
			}

			$(this).wrap('<a href="#" rel="fancybox-galerie"/>')
				.parent().attr('href', img);
			
		}		
		
	});
	$('a[rel=fancybox-galerie]').fancybox({
		'transitionIn'		: 'elastic',
		'transitionOut'		: 'elastic',
		'titlePosition'		: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			return (title.length ? title+'&nbsp; ' : '') + '( '+(currentIndex + 1) + ' / ' + currentArray.length+' )';
		}
	});
});